// page/pack-service/pages/casual-photo/casual-photo.js
var toolUtils = require("../../../../utils/tool-utils.js")
var that;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNum:0,
    tabBar: [{
      name: 1,
      value: '爆料列表',
      iconPath: "/pic/news-list1.png",
      selectedIconPath: "/pic/news-list.png",
      checked: true
    }, {
      name: 2,
      value: '新增爆料',
      iconPath: "/pic/add_news.png"
    }, {
      name: 3,
      value: '我的爆料',
      iconPath: "/pic/my_news1.png",
      selectedIconPath: "/pic/my_news.png"
    }],
    list:[{
      type:1,
      txt:'平定天宁公园为双塔安装了景观灯，而路灯损坏约半年时间无人过问，请问哪个部门负责......',
      imgs: [{
        url: 'https://img.darongshutech.com/20180302145629_rmrb.png'
      }, {
        url: 'https://img.darongshutech.com/20180302145717_rmrb.png'
      }, {
        url: 'https://img.darongshutech.com/20180302145747_rmrb.png'
      }]
    }, {
      type: 0,
      txt: '华阳街道万达中路177号原村委公共卫生间上次我爆料的脏，小便堵塞导致这么副样子......',
      imgs: [{
        url: 'https://img.darongshutech.com/20180302145629_rmrb.png'
      }, {
        url: 'https://img.darongshutech.com/20180302145717_rmrb.png'
      }, {
        url: 'https://img.darongshutech.com/20180302145747_rmrb.png'
      }]
      }, {
        type: 0,
        txt: '华阳街道万达中路177号原村委公共卫生间上次我爆料的脏，小便堵塞导致这么副样子......',
        imgs: [{
          url: 'https://img.darongshutech.com/20180302145629_rmrb.png'
        }, {
          url: 'https://img.darongshutech.com/20180302145717_rmrb.png'
        }, {
          url: 'https://img.darongshutech.com/20180302145747_rmrb.png'
        }]
      }],
    list3: [{
      type: 1,
      txt: '平定天宁公园为双塔安装了景观灯，而路灯损坏约半年时间无人过问，请问哪个部门负责......',
      imgs: [{
        url: 'https://img.darongshutech.com/20180302145629_rmrb.png'
      }, {
        url: 'https://img.darongshutech.com/20180302145717_rmrb.png'
      }, {
        url: 'https://img.darongshutech.com/20180302145747_rmrb.png'
      }]
    }],
    imgs:[""]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          windowHeight: res.windowHeight
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  /**
   * 查看爆料详情
   */
  onDetails:function(e){
    toolUtils.pageTo("/page/pack-service/pages/tip-off-detail/tip-off-detail")
  },
  /**
   * tabBar切换
   */
  tabBarChange: function (e) {

    var index = e.detail.dataset.index
    var tabBar = that.data.tabBar
    if (index == 0) {
      wx.setNavigationBarTitle({
        title: '平安随手拍',
      })
    } else if (index == 1) {
      wx.setNavigationBarTitle({
        title: '新增',
      })
    } else {
      wx.setNavigationBarTitle({
        title: '我的爆料',
      })
    }
    that.setData({
      tabBar: tabBar,
      pageNum:index
    })
  },
  /**
  * 选择照片
  */
  onClicks: function (e) {
    var that = this;
    var images = that.data.imgs;
    switch (e.currentTarget.id) {
      case 'addImgs':
        var num = 9 - images.length + 1;
        wx.chooseImage({
          count: num, // 默认9
          sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
          success: function (res) {
            // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
            var tempFilePaths = res.tempFilePaths
            images.pop();
            Array.prototype.push.apply(images, tempFilePaths);
            var length = images.length
            if (length < 9) {
              images.push('')
            }
            that.setData({
              imgs: images
            })
          }
        })
        break;
      case 'cancelImg':
        images.splice(e.currentTarget.dataset.index, 1)
        that.setData({
          imgs: images
        })
        break;
    }

  }
})